{extend name="default/base" /}

{block name="title"}111{/block}
{block name="keywords"}2222{/block}
{block name="description"}33333{/block}

{block name="css"}{/block}

{block name="content"}
<div class="login-box">
  <div class="login-logo">
    会员登陆
  </div>
  <div class="login-box-body">
    <div class="login-box-msg"></div>
    <form action="" method="post">
      <div class="form-group has-feedback">
        <input type="text" name="username" class="form-control" placeholder="Username">
        <span class="glyphicon glyphicon-user form-control-feedback"></span>
      </div>
      <div class="form-group has-feedback">
        <input type="password" name="password" class="form-control" placeholder="Password">
        <span class="glyphicon glyphicon-lock form-control-feedback"></span>
      </div>
      
      {if condition="is_captcha(2)"}
      <div class="form-group has-feedback">
            <div class="row">
              <div class="col-xs-6">
                <input type="text" name="verify_code" class="form-control" placeholder="验证码">
              </div>
              <div class="col-xs-6">
              {:captcha_img()}
              </div>
            </div>
      </div>
      {/if}
      <div class="row">
        <div class="col-xs-6">
            <a href="{:url('index/member/register')}" class="btn btn-default btn-block btn-flat btn-sm">注册</a>
        </div>
        <!-- /.col -->
        <div class="col-xs-6">
          <button id="submit" type="button" class="btn btn-primary btn-block btn-flat btn-sm">登陆</button>
        </div>
        <!-- /.col -->
      </div>
    </form>
  </div>
  <!-- /.login-box-body -->
</div>
<!-- /.login-box -->

{/block}

{block name="js"}
<script>
$("#submit").click(function(){
    login();
});

document.onkeydown = function (event) {
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if (e && e.keyCode == 13) {
        login();
    }
};

function login() {
    $.ajax({
        type:'post',
        url: "{:url('api/passport/login')}",
        data: {username:$("[name='username']").val(),password:$("[name='password']").val(),verify_code:$("[name='verify_code']").val()},
        success: function(r){
            if(r.code == 200){
                $(".login-box-msg").html('<span class="text-blue">'+r.msg+'</span>');
                window.location.href="{:url('index/member/setting')}";
            } else {
                $(".login-box-msg").html('<span class="text-red">'+r.msg+'</span>');
            }
        }
    });
}
</script> 
{/block}